<template>
  <router-view v-slot="{ Component, route }">
    <!-- <transition :name="appStore.pageAnim + '-transform'" mode="out-in" appear> -->
    <keep-alive :max='10'>
      <component :is="Component" :key="route.fullPath" />
    </keep-alive>
    <!-- </transition> -->
  </router-view>
</template>

<script lang="ts">
import useUserStore from '@/store/modules/user';
import { Form, Message, Modal } from '@arco-design/web-vue';
import { post, get } from '@/api/http'
import useAppConfigStore from '@/store/modules/app-config'
import useCachedRouteStore from '@/store/modules/cached-routes'
import emitter from '@/hooks/useEventBus'
import { defineComponent, onMounted, onUnmounted } from 'vue'
export default defineComponent({
  name: 'Main',
  setup() {
    const appStore = useAppConfigStore()
    const cacheRoutes = useCachedRouteStore()
    let interval = window.setInterval(() => {
      //axios.config里的拦截请求触发了就不会触发这个
      let isSignOut = localStorage.getItem('isSignOut')
      if (isSignOut == "false") {
        // 定数请求
        get({
          url: "admin/acl/user/checkToken",
        })
          .then(({ data, code, message }: any) => {

            if (code === 200) {
              // clearInterval(interval);

            } else {
              Message.error({
                content: message,
                duration: 5000
              });
              setTimeout(() => {
                useUserStore().logout().then(() => {
                  location.reload()
                })
              }
                , 5000)

            }

          })
          .catch(console.log).finally(() => {

          })
      }
    }, 1000 * 5)
    onMounted(() => {
      window.addEventListener('resize', () => {
        emitter.emit('window-change')
      })

    })
    onUnmounted(() => {
      clearInterval(interval)
    })
    return {
      appStore,
      cacheRoutes,
    }
  },
})
</script>
<style lang="less"></style>
